import 'dart:async'; // event bus需要
import 'package:flutter/material.dart';
import 'package:hello/events/demo_event.dart';

class DataSharingSub1Page extends StatefulWidget {
  DataSharingSub1Page({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _DataSharingSub1PageState createState() => _DataSharingSub1PageState();
}

class _DataSharingSub1PageState extends State<DataSharingSub1Page> {

  num _count = 0;

  @override
  void initState(){
    super.initState();
    
  }

  void navigateNamed(String name){
    Navigator.pushNamed(context, name);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('count = $_count'),
            FlatButton(
                child: Text("点我加一（EventBus方式通知上一页）"),
                textColor: Colors.blueGrey,
                onPressed: (){
                  setState(() {
                    _count ++;
                  });
                  //发送订阅消息去修改count
                  eventBus.fire(DemoEvent(_count));
                }),
            
          ],
        ),
      ),
    );
  }
}
